<?php

define('G_BIN_CHECK_INCLUDE', 1);
include "./common.inc.php";

function get_row()
{
	$sql = "UPDATE a2417006_app.img_pic_collection_tmp_tbl SET img_item_id = 0 WHERE img_item_id BETWEEN 1000 AND ".(time() - 300).";";
	$sql .= "SELECT * FROM a2417006_app.img_pic_collection_tmp_tbl WHERE img_item_id=0 ORDER BY add_time ASC LIMIT 0, 1";

	$list = db_query_sql($sql, 2, false);

	$list = $list[0];

	$sql = "UPDATE a2417006_app.img_pic_collection_tmp_tbl SET img_item_id = {$_SERVER['REQUEST_TIME']} WHERE url_hash='{$list[0]['url_hash']}'";
	db_query_sql($sql, 2, false);
	$affected = db_get_affected_rows();
	if($affected[0] == 0)
	{
		return false;
	}
	return $list[0];
}
for($i = 0; $i < 20; $i ++)
{
	$row = get_row();
	if($row == false)
	{
		continue;
	}
	break;
}
if($row == false)
{
	echo json_encode(array('error'=>1));
}
else
{
	$row['error'] = 0;
	echo json_encode($row);
}
